<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <script src="../index.js"></script>
</head>
<body>
<div id="w1" style="border: 1px solid red"></div>
<div id="w2" style="border: 1px solid green"></div>
<script>
var html =
`
<div class="demo">
    <ul>
    <% for(var i=0; i<data.length; i++){ %>
    <li><%= data[i] %></li>
    <% } %>
    </ul>
</div>
`;

var x = new XTemplate();
x.compile(html);

// 使用
var ret = x.run([1, 2, 3, 4, 5]);
document.getElementById('w1').innerHTML = ret;

// 编译完一次模板后 第二次使用不用再重新编译
ret = x.run([4, 5, 6]);
document.getElementById('w2').innerHTML = ret;
</script>
</body>
</html>